﻿@model IEnumerable<FCNS.ERP.Models.ErpCategoryCorS>

@{
    ViewBag.Title = "客商分类";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>@ViewBag.Title</h2>
<script src="~/Scripts/TreeView/bootstrap-treeview.js"></script> 
<link href="~/Content/TreeView/bootstrap-treeview.css" rel="stylesheet" />
<script type="text/javascript">  
    var objList =@Html.Raw(ViewData["ObjList"])   
        function buildDomTree() {
            var data = [];
            function walk(parentId, data) {
                $.each(objList, function (id, node) {
                    if (node[0] == parentId) {
                        var obj = {
                            id: node[1],
                            text: node[2],
                            tags: ['<a href="CategoryCorSEdit/' + node[1] + '">编辑</a>  <a href="CategoryCorSDelete/' + node[1] + '" class="objDelete" > 删除</a>']
                        };
                        //检查是否存在子项
                        var hasChild = false;
                        $.each(objList, function (idChild, nodeChild) {
                            if (nodeChild[0] == node[1]) {
                                hasChild = true;
                                return false;
                            }
                        });
                        if (hasChild == true) {
                            obj.nodes = [];
                            walk(node[1], obj.nodes);
                        }
                        data.push(obj);
                    }
                });
            }

            walk('-1', data);
            return data;
        }

    $(document).ready(function () { 
        var options = {
            bootstrap2: true,
            showTags: true,
            enableLinks: true,
            levels:1,
            data: buildDomTree(objList)
        };

        $('#treeview').treeview(options);

        //所有列表的删除按钮提示框
        $(".objDelete").on("click", function () {
            if (confirm("确定要删除吗?") == false) {
                return false;
            }
        });
    });
</script>
<p>
    <a class="newObjA" href="/Category/CategoryCorSNew">新增</a> 
</p>

<div id="treeview"></div>
